package com.example.estest.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @authr gaoxiaoqi
 * @Date 2022/5/30 13:58
 */
@Configuration
@Slf4j
public class ESconfig {

    @Value("${elasticsearch.host:175.178.2.78}")
    private String host;

    @Value("${elasticsearch.port:9200}")
    private Integer port;

    @Bean
    public RestHighLevelClient restHighLevelClient(){
        String ip = "http://" + host + ":" + port;
        log.info("连接RestHighLevelClient,ip:,{}",ip);
        HttpHost httpHost = new HttpHost(host,port,"http");
        return new RestHighLevelClient(RestClient.builder(httpHost));
    }
}
